//
//  HomePageSearchResturantTableViewCell.m
//  Taste
//
//  Created by 徐昊 on 16/9/23.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "HomePageSearchResturantTableViewCell.h"
#import "HomePageSearchResultContent.h"
#import "UIImageView+WebCache.h"
#import "NSString+Vali.h"

@interface HomePageSearchResturantTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *pic;
@property (weak, nonatomic) IBOutlet UILabel *restaurantName;
@property (weak, nonatomic) IBOutlet UILabel *restaurantAvgprice;
@property (weak, nonatomic) IBOutlet UILabel *shortContent;
@property (weak, nonatomic) IBOutlet UILabel *cityName;

@end

@implementation HomePageSearchResturantTableViewCell

- (void)setContent:(HomePageSearchResultContent *)content {
    _content = content;
    [_pic sd_setImageWithURL:[NSURL URLWithString:[NSString imageWebWithStr:_content.pic]] placeholderImage:[UIImage imageNamed:@"IMG_Universal_Placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    _restaurantName.text = _content.restaurant_name;
    _restaurantAvgprice.text = _content.restaurant_avgprice;
    _shortContent.text = _content.short_content;
    _cityName.text = _content.city_name;
    NSRange range = [_shortContent.text rangeOfString:_searchString];
    NSRange range2 = [_restaurantName.text rangeOfString:_searchString];
    [self setTextColor:_restaurantName FontNumber:[UIFont systemFontOfSize:15] AndRange:range2 AndColor:[UIColor redColor]];
    [self setTextColor:_shortContent FontNumber:[UIFont systemFontOfSize:15] AndRange:range AndColor:[UIColor redColor]];
}
//设置不同字体颜色
-(void)setTextColor:(UILabel *)label FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label.text];
    //设置字号
    [str addAttribute:NSFontAttributeName value:font range:range];
    //设置文字颜色
    [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
    
    label.attributedText = str;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
